package com.jerry.huihome.module.find.fragment;

import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import com.jerry.huihome.R;
import com.jerry.huihome.base.BaseFragment;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/10.
 */
public class FindFragment extends BaseFragment{

    @BindView(R.id.rg_find)
    RadioGroup rgFind;
    @BindView(R.id.fl_find)
    FrameLayout flFind;
    private DesignerFragment fragment;
    private String tag;
    private Map<String, String> params;

    @Override
    protected int getLayoutId(){
        return R.layout.fragment_find;
    }

    @Override
    protected void initViews(){
        params = new HashMap<>();
        params.put("tag", tag);
        if(tag == "place"){
            ConstructionFragment constructionFragment = BaseFragment.newInstance(ConstructionFragment.class, params);
            getChildFragmentManager().beginTransaction().replace(R.id.fl_find, constructionFragment).commit();
        }else{
            fragment = BaseFragment.newInstance(DesignerFragment.class, params);
            getChildFragmentManager().beginTransaction().replace(R.id.fl_find, fragment).commit();
        }
        rgFind.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId){
                switch(checkedId){
                    case R.id.rb_designer:
                        if(fragment == null){
                            fragment = BaseFragment.newInstance(DesignerFragment.class, params);
                        }
                        getChildFragmentManager().beginTransaction().replace(R.id.fl_find, fragment).commit();
                        break;
                    case R.id.rb_construction:
                        ConstructionFragment constructionFragment = BaseFragment.newInstance(ConstructionFragment.class, params);
                        getChildFragmentManager().beginTransaction().replace(R.id.fl_find, constructionFragment).commit();
                        break;
                }
            }
        });
    }

    @Override
    protected void getReqParams(Bundle bundle){
        tag = bundle.getString("tag");
    }
}
